<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



<!-- rows -->
<div class="row">
    <!-- NEW WIDGET START -->
    <article class="col-sm-12 col-md-12 col-lg-12">
        <div class="jarviswidget well" id="wid-id-3"
            data-widget-colorbutton="false"
            data-widget-editbutton="false"
            data-widget-togglebutton="false"
            data-widget-deletebutton="false"
            data-widget-fullscreenbutton="false"
            data-widget-custombutton="false"
            data-widget-sortable="false">
            <!-- widget div-->
            <div>
                <div class="widget-body">
                    <a class="btn btn-default" id="btn-re-common" href="javascript:void(0)"><i class="fa fa-lg fa-mail-reply-all"></i> 流程明细</a>

                    <ul id="myTab1" class="nav nav-tabs bordered  ">
                        <li class="active">
                            <a href="#s1" id="first1" data-toggle="tab"><i class="fa fa-fw fa-lg fa-credit-card"></i> 基本设置 </a>
                        </li>
                        <li class="disabled">
                            <a href="#s2" id="other1" data-toggle="tab"><i class="fa fa-fw fa-lg fa-th-list"></i>步骤列表 </a>
                        </li>
                    </ul>

                    <div id="myTabContent1" class="tab-content padding-10 ">
                        <div class="tab-pane fade in active " id="s1" style="margin: 10px;">
                            <hr class="simple">
                            <form id="formConfig" class="smart-form" novalidate="novalidate" action="" method="post">
                                <input type="hidden" name="keyId" id="keyId" value="<s:property value="keyId" />">
                                <input type="hidden"  id="archReaderId" name="archReaderId" value="<s:property value="creadConfig.id" />">
                                <input type="hidden"  id="archEditorId" name="archEditorId" value="<s:property value="ceditConfig.id" />">
                                <input type="hidden"  id="docReaderId"  name="docReaderId" value="<s:property value="cdocConfig.id" />">
                                <a class="btn btn-default pull-right pull-right-fix" id="btn-config-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存</a>
                                <header id="title" style="display: block;">
                                   流程简要表
                                </header>
                                <fieldset >
                                    <div class="row">
                                        <label class="label col col-2">流程名称：</label>
                                        <section class="col col-5">
                                            <label class="input">
                                                <input type="text"  name="processName" id="processName"
                                                       value="<s:property value="processBrief.name"/>">
                                            </label>
                                        </section>
                                    </div>
                                    <div class="row">
                                        <label class="label col col-2">关联表单：</label>
                                        <section class="col col-5">
                                            <label class="input">
                                                <select class="form-control" name="tableKey" id="tableKey">
                                                    <option value=""></option>
                                                    <s:iterator value="entityDatas" id="list">
                                                        <option  value="<s:property value="#list.key"/>" <s:property value="#list.selected"/> ><s:property value="#list.value"/></option>
                                                    </s:iterator>
                                                </select>
                                            </label>
                                        </section>
                                    </div>


                                    <header style="display: block;">
                                        文档归档后配置

                                        <a key="archReader_href" href="javascript:void(0);">
                                            <span class="txt-color-blueDark pull-right">
                                                    <i class="fa-fw fa fa-wrench"></i> 读者类型<span></span>
                                            </span>
                                        </a>
                                        <a key="archEditor_href" href="javascript:void(0);">
                                            <span class="txt-color-blueDark pull-right">
                                                    <i class="fa-fw fa fa-wrench"></i> 编辑者类型<span></span>
                                            </span>
                                        </a>
                                    </header>

                                    <div class="row">
                                        <label class="label col col-2" style="color:#4FA5D0">读者：</label>
                                    </div>
                                     <div id="archReaderDiv" >
                                     </div>
                                     <div class="row">
                                        <label class="label col col-2" style="color:#4FA5D0">编辑者：</label>
                                     </div>
                                      <div id="archEditorDiv">
                                      </div>
                                    <header style="display: block;">
                                        其他设置
                                        <a key="docReader_href" href="javascript:void(0);">
                                            <span class="txt-color-blueDark pull-right">
                                                    <i class="fa-fw fa fa-wrench"></i> 文档阅览者<span></span>
                                            </span>
                                        </a>
                                    </header>
                                    <div id="docReaderDiv">

                                    </div>
                                </fieldset>

                            </form>
                        </div>
                        <div class="tab-pane fade in active" id="s2" style="margin: 10px;"></div>
                    </div>
                </div>
            </div>
        </div>
    </article>
</div>


<script type="text/javascript">
pageSetUp();
var keyId = $('#keyId').val();
if(keyId != ""){
    $('#other1').parent('li').removeClass('disabled');
}
var table_global_width=0;
$("a#other1").off("click").on("click",function(e) {
    if(keyId != "") {
        if (table_global_width == 0) {
            table_global_width = $("#s1").is(":visible") ? $("#s1").width() : $("#s2").width();
        }
        loadURL("../com/ajax!stepBrief.action?parentId=" + $("#keyId").val(), $('div#s2'));
    }else{
        return false;
    }
});

$('a#first1').off("click").on("click",function(e) {
    $('div#s2').empty();
});
//返回
$("#btn-re-common").click(function(){
    loadURL("../com/ajax!processBrief.action",$('#content'));
});
//保存流程简要表
$("#btn-config-save-common").click(function(){
    var $valid = $("#formConfig").valid();
    if(!$valid) return false;
    form_save("formConfig","<%=path%>/com/ajax-processbrief!save.action");
    loadURL("../com/ajax!processBrief.action",$('#content'));
});
//添加步骤简要表
/*
$('#btn-add-step').click(function(){
    var keyId = $('#keyId').val();
    if(keyId == ""){
        alert("请先保存流程简要表");
    }
    gDialog.fCreate({
        title:'节点配置',
        url:actionUrl,
        width:800
    }).show();
    loadURL("ajax-stepbrief!input.action?parentId="+keyId, $('#content'));
})*/
</script>
<script>
    $.validator.methods.compareDate = function(value, element) {
        var date1 = new Date();
        var date2 = new Date(Date.parse(value.replace("-", "/")));
        return date1 <= date2;
    };
 //校验
 $("#formConfig").validate({
     rules : {
         processName : {
             required : true
         },
         tableKey:{
             required : true
         }
     },
     messages : {
         processName : {
             required : '请填写流程名称'
         },
         tableKey:{
             required : '请选择关联表单'
         }
     },
     errorPlacement : function(error, element) {
         error.insertAfter(element.parent());
     }
 });

</script>

<script>

    $("a[key$='_href']").unbind("click").bind("click",function(){
        var key = $(this).attr("key");
        var type = key.split("_")[0];
        // console.debug(type);
        var tableKey = $('#tableKey').val();
        var keyId = $("input#"+type+"Id").val();
        var actionUrl = "../com/ajax-commoncfg!input.action";
        $(this).leftview('init',{
            title:"配置权限",
            data:{keyId:keyId,selectType:type,tableKey:tableKey},
            actionUrl:actionUrl
        });
    });
    $('.hasDatepicker').datetimepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        language: 'zh-CN',
        minView:2
    });

    $(function(){
        loadURL("../com/ajax-commoncfg!read.action?keyId="+$("#archReaderId").val(),$("#archReaderDiv"));
        loadURL("../com/ajax-commoncfg!read.action?keyId="+$("#archEditorId").val(),$("#archEditorDiv"));
        loadURL("../com/ajax-commoncfg!read.action?keyId="+$("#docReaderId").val(),$("#docReaderDiv"));
    });
</script>
